<template>
<div>
  <el-dialog
    title="预设解除原因"
    :close-on-click-modal="false"
    append-to-body
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" label-width="0px">
      <el-row  :gutter="15">
        <el-col :span="16">
          <ul class="infinite-list" style="overflow:auto">
            <li v-for="(msg,index) in presetList" class="infinite-list-item uni-flex">
              <!-- <el-tooltip effect="dark" :content="msg" placement="top"> -->
              <div class="uni-preset uni-ellipsis"> {{msg}}</div>
              <!-- </el-tooltip> -->
              <div class="uni-delete" @click="deleteItem(index)">删除</div>
            </li>
          </ul>
        </el-col>
        <el-col :span="8">
          <el-form-item label="" prop="relieveCause" style="margin-bottom: 10px;"
            :rules="[
              {required: true, message:'预设解除原因不能为空', trigger:'blur'}
             ]">
            <el-input type="textarea" rows="8" v-model="inputForm.relieveCause" placeholder="请填写预设解除原因"     ></el-input>
          </el-form-item>
          <el-button style="float: right;" size="mini" round plain @click="addpreset()" v-noMoreClick>添加预设</el-button>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" @click="doSubmit()" v-noMoreClick>保存</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        loading: false,
        inputForm: {
          relieveCause: ''
        },
        presetList: [],
      }
    },
    components: {
    },
    methods: {
      init() {
        this.visible = true
        this.$http({
          url: '/smis/config/jfConfig/queryByKey',
          method: 'post',
          params: {
            'keyStr': "presetConfig"
          }
        }).then(({
          data
        }) => {
          if (data && data.success) {
            for(var key in (data.data||{})) {
              if(this.$data.hasOwnProperty(key)) {
                this.$data[key] = data.data[key]
              }
            }
          }
        })
      },
      addpreset() {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.presetList.unshift(this.inputForm.relieveCause)
          }
        })
      },
      deleteItem(index) {
        this.presetList.splice(index,1);
      },
      doSubmit () {
        this.loading = true
        var inputForm = {
          presetList: this.presetList
        }
        this.$http({
          url: `/smis/config/jfConfig/saveConfig`,
          method: 'post',
          data: {
            keyStr: 'presetConfig',
            valueStr: JSON.stringify(inputForm)
          }
        }).then(({
          data
        }) => {
          if (data && data.success) {
            // this.refreshList()
            this.visible = false
            this.$message.success(data.msg)
            this.$emit('refreshPresetList', this.presetList)
          }
          this.loading = false
        })
      }
    }
  }
</script>
<style scoped="">
  .infinite-list {
    width: 100%;
    height: 200px;
    font-size: 12px;
    line-height: 20px;
    color: #777777;
  }
  .infinite-list-item {
    justify-content: space-between;
  }
  .uni-preset {
    width: 90%;
  }
  .uni-delete {
    color: #F56C6C;
    width: 30px;
  }
</style>
